home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / GRAPHICS / TS32 / TS32.ZIP / Missile.pas < prev    next >
Pascal/Delphi Source File  |  1996-03-14  |  2KB  |  88 lines

  1. unit Missile;
  2.  
  3. (*********************************************
  4. TMissile->TSprite
  5.  
  6. This sprite descends directly from TSprite, and
  7. has its own custom Render method that simply
  8. sets pixels in the video buffer.  This is a re-
  9. usable sprite class that is not specific to any
  10. app.
  11. *********************************************)
  12.  
  13. interface
  14.  
  15. uses
  16.   Windows, SysUtils, Classes, Graphics, Controls, DibDrawingSurface,
  17.   Sprite, DIB, DIBSprite, Utility;
  18.  
  19. type
  20.  
  21.   TMissile = class( TSprite )
  22.   private
  23.      nLife: word;
  24.      nColor: byte;
  25.      nMaxLife: word;
  26.   protected
  27.   public
  28.      constructor CreateMissile( nMax: word; nColorOffset: byte );
  29.      procedure Move; override;
  30.      procedure Render; override;
  31.   end;
  32.  
  33. implementation
  34.  
  35. constructor TMissile.CreateMissile( nMax: word; nColorOffset: byte );
  36. begin
  37.   inherited Create;
  38.   nLife := 0;
  39.   nColor := nColorOffset;
  40.   Priority := 1;
  41.   Speed := 8;
  42.   nMaxLife := nMax;
  43.   MotionType := mtContinuous;
  44.   Width := 3;
  45.   Height := 3;
  46. end;
  47.  
  48. procedure TMissile.Move;
  49. begin
  50.   Inc( nLife );
  51.   if nLife = nMaxLife then
  52.      Dead := TRUE;
  53.   inherited Move;
  54. end;
  55.  
  56. procedure TMissile.Render;
  57. var
  58.   n: byte;
  59. begin
  60.   inherited Render;
  61.   n := Random( 16 ) + nColor;
  62.   with ptPhysical, dds do
  63.      begin
  64.         if ( X - 2 >= 0 ) and ( Y - 2 >= 0 ) and
  65.            ( X + 2 < PhysicalWidth ) and ( Y + 2 < PhysicalHeight ) then
  66.            begin
  67.               with DIBCanvas do
  68.                  begin
  69.                     Pixels[X, Y] := n;
  70.                     Pixels[X, Y - 1] := n;
  71.                     Pixels[X, Y + 1] := n;
  72.                     Pixels[X - 1, Y] := n;
  73.                     Pixels[X + 1, Y] := n;
  74.                     Pixels[X - 1, Y - 1] := n;
  75.                     Pixels[X - 1, Y + 1] := n;
  76.                     Pixels[X + 1, Y - 1] := n;
  77.                     Pixels[X + 1, Y + 1] := n;
  78.                     Pixels[X, Y - 2] := n;
  79.                     Pixels[X, Y + 2] := n;
  80.                     Pixels[X - 2, Y] := n;
  81.                     Pixels[X + 2, Y] := n;
  82.                  end;
  83.            end;
  84.      end;
  85. end;
  86.  
  87. end.
  88.